package com.wang.controller;

import com.alibaba.fastjson.JSON;
import com.wang.entity.User;
import com.wang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 愿青春不负梦想
 * @Description: TODO
 * @email 3062827964@qq.com
 * @date 2023-01-20 18:58
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    @Qualifier("UserServiceImpl")
    private UserService userService;

    @RequestMapping("/hello")
    public String list() {
        return "allBook";
    }

    @RequestMapping("/allUser")
    public String getAllUser() {
        List<User> users = userService.queryAllUser();
        for (User user : users) {
            System.out.println(user.toString());
        }

        // 返回对象前一定要先转为JSON
        return JSON.toJSONString(users);
    }
}
